$(function(){

    $('#register-btn').on('click',function(){
        var username = $('[name="username"]').val();
        var mobile = $('[name="mobile"]').val();
        var password = $('[name="password"]').val();
        var againPass = $('[name="againPass"]').val();
        var vCode = $('[name="vCode"]').val();

        if(!username){
            mui.toast('请输入用户名');
            return;
        }
        if(mobile.length < 11){
            mui.toast("请输入合法的手机号");
            return;
        }
        if(password != againPass){
            mui.toast('两次输入的密码不一样')
            return;
        }
        if(vCode.length != 6){
            mui.toast('认证码不合法');
            return;
        }

        $.ajax({
            type: "post",
            url: "/user/register",
            data: {
                username: username,
                password:password,
                mobile:mobile,
                vCode: vCode
            },
            success: function (response) {
                console.log(response);
                alert("注册成功");
                setTimeout(function(){
                    location.href = "login.html";
                },2000);
            }
        });



    });

    $("#getCode").on('click',function(){
        $.ajax({
            type: "get",
            url: "/user/vCode",
            success: function (response) {
                console.log(response.vCode)
            }
        });
    });
});
